<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<div class="button_area">
	<a href="customerCompany/customerCompany.info.action" class="button">添加</a>
</div>
<div class="filter_area">
	<s:form>
		<tr>
			<td>
				<table>
					<s:textfield label="企业名称" id="code" name="filter.companyName" size="10"></s:textfield>
				</table>
			</td>
			<td>
				<table>
					<s:textfield label="公司地址" id="code" name="filter.address" size="10"></s:textfield>
				</table>
			</td>
			<td>
				<table>
					<s:textfield label="联系电话" id="description" name="filter.phoneNumber" size="10"></s:textfield>
				</table>
			</td>

			<td width="20px"></td>
			<td style="padding-bottom: 6px" valign="bottom">
					<a href="javascript:void(0)" onclick="GridOption.doSearch()">搜索</a>
			</td>
		</tr>

	</s:form>
</div>

<script type="text/javascript">
var GridOption={        
			url:'customerCompany/customerCompanyList.action?'+$('form').serialize(),
     		datatype: 'json',  
     		jsonReader:{ root: "dataRows"},   
    		colModel:[       
       			{label:'id',name:'custCompanyId',index:'custCompanyId',key:true, hidden:true},     
       			{label:'企业名称',name:'custCompanyName',index:'custCompanyName',required:true, width:100,editable:false,formatter:'showlink', formatoptions:{baseLinkUrl:'customerCompany/customerCompany.info.action'}},     
        		{label:'地址',name:'address',index:'address', width:100,editable:false},       
        		{label:'联系电话',name:'phoneNumber',index:'phoneNumber', width:100,editable:false},
        		{label:'传真',name:'faxNumber',index:'faxNumber', width:100,editable:false},     
        		{label:'邮政编码',name:'postalCode',index:'postalCode', width:100,editable:false},      
        		{label:' ',name:'del', width:100,align:'center',sortable:false}
     		],     
     		imgpath: '../theme/images/jqgrid/',      
    		pager: "#pjmap",   
      		multiselect: false,     
     		sortname: 'custCompanyId',     
      		viewrecords: true,     
      		sortorder: "desc",     
      		jsonReader: {     
	      		root: "dataRows",
	      		repeatitems : false
     		},
     		gridComplete: function(){
				var ids = jQuery("#list").jqGrid('getDataIDs');
				for(var i=0;i < ids.length;i++){
					var cl = ids[i];
					var data=jQuery("#list").jqGrid('getRowData',cl);
					if(data.deleted=='true'){
						if(!data.loginId.startWith('<img') && !data.loginId.startWith('<IMG')){
							cd='<img style="border:1px" src="theme/images/del.gif" title=""/>'+data.loginId;
						}else{
							cd=data.loginId;
						}
						sc= "<a href='javascript:void(0)' onclick=\"GridOption.doRedeleted("+cl+");\">恢复</a>";
						jQuery("#list").jqGrid('setRowData',ids[i],{loginId:cd,del:sc});
					}else{
						sc= "<a href='javascript:void(0)' onclick=\"GridOption.doDelete("+cl+");\">删除</a>";
						jQuery("#list").jqGrid('setRowData',ids[i],{del:sc});
					}
				}
			},
    		width:$(document).width()-80,
    		height: $(document).height()-160,
    		doDelete:function(id){
    			var data=jQuery("#list").jqGrid('getRowData',id);
    			$("#list").delGridRow(id,{url:'customerCompany/customerCompanyDelete.action',caption:'请确认',msg:'确认删除 "'+data.custCompanyName+'" 吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
    			
    		},
    		doRedeleted:function(id){
    			var data=jQuery("#list").jqGrid('getRowData',id);
    			$("#list").delGridRow(id,{url:'customerCompany/customerCompanyDelete.action',caption:'请确认',msg:'确认恢复 "'+data.custCompanyName+'" 吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
    			$("#list").trigger("reloadGrid");
    		},
    		doSearch:function(){
    			$("#list").setGridParam({url:"customerCompany/customerCompanyList.action?"+$('form').serialize()});
      			$("#list").trigger("reloadGrid");
    		},
    		subGrid: true, 
    		subGridRowExpanded: function(subgrid_id, row_id) { 
    		 var subgrid_table_id, pager_id; 
    		 subgrid_table_id = subgrid_id+"_t";
    		  pager_id = "p_"+subgrid_table_id;
    		   $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
    		   jQuery("#"+subgrid_table_id).jqGrid({ 
    		   	url:"customerCompany/customer.list.action?id="+row_id, 
    		   	datatype: "json",
    		   jsonReader: {     
	      				root: "dataRows",
	      				repeatitems : false
     				},
 				colModel:[     
        		{label:'id',name:'customerId',index:'customerId',key:true, hidden:true},     
       			{label:'姓名',name:'customerName',index:'customerName',sortable:false},     
        		{label:'性别',name:'sex',index:'sex',sortable:false},
        		{label:'职位',name:'position',index:'position.dictionaryName',sortable:false},  
        		{label:'联系电话',name:'phoneNumber',index:'phoneNumber',sortable:false},
        		{label:'电邮地址',name:'email',index:'email',sortable:false}
      				],  
    		    height: '100%' 
    		    });
    		   }
    };

</script>
